package com.nache.activity;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.model.GraphUser;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class LoginPage extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	  setContentView(R.layout.activity_loginpage);

    	  // start Facebook Login
    	  Session.openActiveSession(this, true, new Session.StatusCallback() {

    	    // callback when session changes state
    	    @Override
    	    public void call(final Session session, SessionState state, Exception exception) {
    	    	if (session.isOpened()) {
    	    		// make request to the /me API
    	    		Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

    	    		  // callback after Graph API response with user object
    	    		  @Override
    	    		  public void onCompleted(GraphUser user, Response response) {
    	    			  
    	    			  if (user != null) {
    	    				  TextView welcome = (TextView) findViewById(R.id.welcome);
    	    				  welcome.setText("Hello " + user.getName() + "!"+session.getAccessToken());
    	    				}
    	    		  }
    	    		});
    	    	}
    	    }
    	  });
    }

    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
    }
    
}
